home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / docs / howto / convertToGcc < prev    next >
Encoding:
Text File  |  1992-12-14  |  1.6 KB  |  62 lines

  1. A couple of quick comments on converting programs to run under gcc,
  2. because these are things I often forget myself:
  3.  
  4. 1.  You need -fwritable-strings if the program assigns string
  5.     constants and then overwrites them.  The most frequent
  6.     culprit is a call to the library routine `mktemp()'.
  7.  
  8. 2.  Pre-processing is different.  Something that does
  9.  
  10.     #define foo(bar) "/x/y/z/bar"
  11.     foo(baz)
  12.  
  13.     will work under the unix cc but not gcc (it will come out "bar"
  14.     instead of expanding the argument to "baz").  You need to use the
  15.     ANSI C `stringify' operator:
  16.  
  17.     #define foo(bar) "/x/y/z/" #bar
  18.     foo(baz)
  19.  
  20.     this will come out as:
  21.  
  22.     "/x/y/z/" "baz"
  23.  
  24.     The compiler will then join these into a single string.
  25.  
  26.     Unfortunately there isn't any `character-constantify' operator
  27.     so something like:
  28.  
  29.     #define CTRL(x)     ('x' & 0x1f)
  30.  
  31.     CTRL(c)
  32.  
  33.     will come out as ('x' & 0x1f) instead of the intended ('c' & 0x1f).
  34.     If you specify the `-traditional' flag the macro will still work.
  35.     The only alternative is to expicitly type the quotes each time:
  36.  
  37.     #define CTRL(x)     (x & 0x1f)
  38.  
  39.     CTRL('c')
  40.  
  41.  
  42. 3.  Token concatanation is different.  With the old cc you could define
  43.     a constant like:
  44.  
  45.     #define ENTRY(label)        .globl _/**/label ; _/**/label:
  46.     ENTRY(foobar)
  47.  
  48.     which would expand to:
  49.  
  50.     .globl _foobar ; _foobar:
  51.  
  52.     But gcc replaces the comment with a space rather that eliding
  53.     it completely.  You can compile with the `-traditional' flag,
  54.     or you can use the `concatenation' operator.
  55.  
  56.     #define ENTRY(label)        .globl _ ## label ; _ ## label:
  57.  
  58.  
  59.     Fred Douglis
  60.     6/13/89
  61.  
  62.